package dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

  
  
/**
 * This class was autogenerated by Torque on:
 *
 * [Fri Jan 09 02:39:32 PST 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Section
 */
public abstract class BaseSection extends BaseObject
{
    /** The Peer class */
    private static final SectionPeer peer =
        new SectionPeer();

        
    /** The value for the sectionid field */
    private int sectionid;
      
    /** The value for the sectionname field */
    private String sectionname;
      
    /** The value for the numberofstudents field */
    private int numberofstudents;
      
    /** The value for the courseid field */
    private int courseid;
  
    
    /**
     * Get the Sectionid
     *
     * @return int
     */
    public int getSectionid()
    {
        return sectionid;
    }

                                              
    /**
     * Set the value of Sectionid
     *
     * @param v new value
     */
    public void setSectionid(int v) throws TorqueException
    {
    
                  if (this.sectionid != v)
              {
            this.sectionid = v;
            setModified(true);
        }
    
          
                                  
        // update associated SectionTeamTeach
        if (collSectionTeamTeachs != null)
        {
            for (int i = 0; i < collSectionTeamTeachs.size(); i++)
            {
                ((SectionTeamTeach) collSectionTeamTeachs.get(i))
                    .setSectionid(v);
            }
        }
                                          
        // update associated SectionLecture
        if (collSectionLectures != null)
        {
            for (int i = 0; i < collSectionLectures.size(); i++)
            {
                ((SectionLecture) collSectionLectures.get(i))
                    .setSectionid(v);
            }
        }
                                          
        // update associated SectionLaboratory
        if (collSectionLaboratorys != null)
        {
            for (int i = 0; i < collSectionLaboratorys.size(); i++)
            {
                ((SectionLaboratory) collSectionLaboratorys.get(i))
                    .setSectionid(v);
            }
        }
                                          
        // update associated SectionRecitation
        if (collSectionRecitations != null)
        {
            for (int i = 0; i < collSectionRecitations.size(); i++)
            {
                ((SectionRecitation) collSectionRecitations.get(i))
                    .setSectionid(v);
            }
        }
                                          
        // update associated Gradesheet
        if (collGradesheets != null)
        {
            for (int i = 0; i < collGradesheets.size(); i++)
            {
                ((Gradesheet) collGradesheets.get(i))
                    .setSectionid(v);
            }
        }
                      }
  
    /**
     * Get the Sectionname
     *
     * @return String
     */
    public String getSectionname()
    {
        return sectionname;
    }

                        
    /**
     * Set the value of Sectionname
     *
     * @param v new value
     */
    public void setSectionname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.sectionname, v))
              {
            this.sectionname = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Numberofstudents
     *
     * @return int
     */
    public int getNumberofstudents()
    {
        return numberofstudents;
    }

                        
    /**
     * Set the value of Numberofstudents
     *
     * @param v new value
     */
    public void setNumberofstudents(int v) 
    {
    
                  if (this.numberofstudents != v)
              {
            this.numberofstudents = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Courseid
     *
     * @return int
     */
    public int getCourseid()
    {
        return courseid;
    }

                              
    /**
     * Set the value of Courseid
     *
     * @param v new value
     */
    public void setCourseid(int v) throws TorqueException
    {
    
                  if (this.courseid != v)
              {
            this.courseid = v;
            setModified(true);
        }
    
                          
                if (aCourse != null && !(aCourse.getCourseid() == v))
                {
            aCourse = null;
        }
      
              }
  
      
    
                  
    
        private Course aCourse;

    /**
     * Declares an association between this object and a Course object
     *
     * @param v Course
     * @throws TorqueException
     */
    public void setCourse(Course v) throws TorqueException
    {
            if (v == null)
        {
                    setCourseid(0);
                  }
        else
        {
            setCourseid(v.getCourseid());
        }
                aCourse = v;
    }

                                            
    /**
     * Get the associated Course object
     *
     * @return the associated Course object
     * @throws TorqueException
     */
    public Course getCourse() throws TorqueException
    {
        if (aCourse == null && (this.courseid > 0))
        {
                          aCourse = CoursePeer.retrieveByPK(SimpleKey.keyFor(this.courseid));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               Course obj = CoursePeer.retrieveByPK(this.courseid);
               obj.addSections(this);
            */
        }
        return aCourse;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setCourseKey(ObjectKey key) throws TorqueException
    {
      
                        setCourseid(((NumberKey) key).intValue());
                  }
       
                                
            
    /**
     * Collection to store aggregation of collSectionTeamTeachs
     */
    protected List collSectionTeamTeachs;

    /**
     * Temporary storage of collSectionTeamTeachs to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initSectionTeamTeachs()
    {
        if (collSectionTeamTeachs == null)
        {
            collSectionTeamTeachs = new ArrayList();
        }
    }

    /**
     * Method called to associate a SectionTeamTeach object to this object
     * through the SectionTeamTeach foreign key attribute
     *
     * @param l SectionTeamTeach
     * @throws TorqueException
     */
    public void addSectionTeamTeach(SectionTeamTeach l) throws TorqueException
    {
        getSectionTeamTeachs().add(l);
        l.setSection((Section) this);
    }

    /**
     * The criteria used to select the current contents of collSectionTeamTeachs
     */
    private Criteria lastSectionTeamTeachsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionTeamTeachs(new Criteria())
     *
     * @throws TorqueException
     */
    public List getSectionTeamTeachs() throws TorqueException
    {
        if (collSectionTeamTeachs == null)
        {
            collSectionTeamTeachs = getSectionTeamTeachs(new Criteria(10));
        }
        return collSectionTeamTeachs;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionTeamTeachs from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getSectionTeamTeachs(Criteria criteria) throws TorqueException
    {
        if (collSectionTeamTeachs == null)
        {
            if (isNew())
            {
               collSectionTeamTeachs = new ArrayList();
            }
            else
            {
                      criteria.add(SectionTeamTeachPeer.SECTIONID, getSectionid() );
                      collSectionTeamTeachs = SectionTeamTeachPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(SectionTeamTeachPeer.SECTIONID, getSectionid());
                      if (!lastSectionTeamTeachsCriteria.equals(criteria))
                {
                    collSectionTeamTeachs = SectionTeamTeachPeer.doSelect(criteria);
                }
            }
        }
        lastSectionTeamTeachsCriteria = criteria;

        return collSectionTeamTeachs;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionTeamTeachs(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionTeamTeachs(Connection con) throws TorqueException
    {
        if (collSectionTeamTeachs == null)
        {
            collSectionTeamTeachs = getSectionTeamTeachs(new Criteria(10), con);
        }
        return collSectionTeamTeachs;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionTeamTeachs from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionTeamTeachs(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collSectionTeamTeachs == null)
        {
            if (isNew())
            {
               collSectionTeamTeachs = new ArrayList();
            }
            else
            {
                       criteria.add(SectionTeamTeachPeer.SECTIONID, getSectionid());
                       collSectionTeamTeachs = SectionTeamTeachPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(SectionTeamTeachPeer.SECTIONID, getSectionid());
                       if (!lastSectionTeamTeachsCriteria.equals(criteria))
                 {
                     collSectionTeamTeachs = SectionTeamTeachPeer.doSelect(criteria, con);
                 }
             }
         }
         lastSectionTeamTeachsCriteria = criteria;

         return collSectionTeamTeachs;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related SectionTeamTeachs from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getSectionTeamTeachsJoinSection(Criteria criteria)
        throws TorqueException
    {
        if (collSectionTeamTeachs == null)
        {
            if (isNew())
            {
               collSectionTeamTeachs = new ArrayList();
            }
            else
            {
                            criteria.add(SectionTeamTeachPeer.SECTIONID, getSectionid());
                            collSectionTeamTeachs = SectionTeamTeachPeer.doSelectJoinSection(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SectionTeamTeachPeer.SECTIONID, getSectionid());
                        if (!lastSectionTeamTeachsCriteria.equals(criteria))
            {
                collSectionTeamTeachs = SectionTeamTeachPeer.doSelectJoinSection(criteria);
            }
        }
        lastSectionTeamTeachsCriteria = criteria;

        return collSectionTeamTeachs;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collSectionLectures
     */
    protected List collSectionLectures;

    /**
     * Temporary storage of collSectionLectures to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initSectionLectures()
    {
        if (collSectionLectures == null)
        {
            collSectionLectures = new ArrayList();
        }
    }

    /**
     * Method called to associate a SectionLecture object to this object
     * through the SectionLecture foreign key attribute
     *
     * @param l SectionLecture
     * @throws TorqueException
     */
    public void addSectionLecture(SectionLecture l) throws TorqueException
    {
        getSectionLectures().add(l);
        l.setSection((Section) this);
    }

    /**
     * The criteria used to select the current contents of collSectionLectures
     */
    private Criteria lastSectionLecturesCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionLectures(new Criteria())
     *
     * @throws TorqueException
     */
    public List getSectionLectures() throws TorqueException
    {
        if (collSectionLectures == null)
        {
            collSectionLectures = getSectionLectures(new Criteria(10));
        }
        return collSectionLectures;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionLectures from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getSectionLectures(Criteria criteria) throws TorqueException
    {
        if (collSectionLectures == null)
        {
            if (isNew())
            {
               collSectionLectures = new ArrayList();
            }
            else
            {
                      criteria.add(SectionLecturePeer.SECTIONID, getSectionid() );
                      collSectionLectures = SectionLecturePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(SectionLecturePeer.SECTIONID, getSectionid());
                      if (!lastSectionLecturesCriteria.equals(criteria))
                {
                    collSectionLectures = SectionLecturePeer.doSelect(criteria);
                }
            }
        }
        lastSectionLecturesCriteria = criteria;

        return collSectionLectures;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionLectures(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionLectures(Connection con) throws TorqueException
    {
        if (collSectionLectures == null)
        {
            collSectionLectures = getSectionLectures(new Criteria(10), con);
        }
        return collSectionLectures;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionLectures from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionLectures(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collSectionLectures == null)
        {
            if (isNew())
            {
               collSectionLectures = new ArrayList();
            }
            else
            {
                       criteria.add(SectionLecturePeer.SECTIONID, getSectionid());
                       collSectionLectures = SectionLecturePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(SectionLecturePeer.SECTIONID, getSectionid());
                       if (!lastSectionLecturesCriteria.equals(criteria))
                 {
                     collSectionLectures = SectionLecturePeer.doSelect(criteria, con);
                 }
             }
         }
         lastSectionLecturesCriteria = criteria;

         return collSectionLectures;
     }

                        
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related SectionLectures from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getSectionLecturesJoinSection(Criteria criteria)
        throws TorqueException
    {
        if (collSectionLectures == null)
        {
            if (isNew())
            {
               collSectionLectures = new ArrayList();
            }
            else
            {
                            criteria.add(SectionLecturePeer.SECTIONID, getSectionid());
                            collSectionLectures = SectionLecturePeer.doSelectJoinSection(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SectionLecturePeer.SECTIONID, getSectionid());
                        if (!lastSectionLecturesCriteria.equals(criteria))
            {
                collSectionLectures = SectionLecturePeer.doSelectJoinSection(criteria);
            }
        }
        lastSectionLecturesCriteria = criteria;

        return collSectionLectures;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related SectionLectures from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getSectionLecturesJoinClassroom(Criteria criteria)
        throws TorqueException
    {
        if (collSectionLectures == null)
        {
            if (isNew())
            {
               collSectionLectures = new ArrayList();
            }
            else
            {
                            criteria.add(SectionLecturePeer.SECTIONID, getSectionid());
                            collSectionLectures = SectionLecturePeer.doSelectJoinClassroom(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SectionLecturePeer.SECTIONID, getSectionid());
                        if (!lastSectionLecturesCriteria.equals(criteria))
            {
                collSectionLectures = SectionLecturePeer.doSelectJoinClassroom(criteria);
            }
        }
        lastSectionLecturesCriteria = criteria;

        return collSectionLectures;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collSectionLaboratorys
     */
    protected List collSectionLaboratorys;

    /**
     * Temporary storage of collSectionLaboratorys to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initSectionLaboratorys()
    {
        if (collSectionLaboratorys == null)
        {
            collSectionLaboratorys = new ArrayList();
        }
    }

    /**
     * Method called to associate a SectionLaboratory object to this object
     * through the SectionLaboratory foreign key attribute
     *
     * @param l SectionLaboratory
     * @throws TorqueException
     */
    public void addSectionLaboratory(SectionLaboratory l) throws TorqueException
    {
        getSectionLaboratorys().add(l);
        l.setSection((Section) this);
    }

    /**
     * The criteria used to select the current contents of collSectionLaboratorys
     */
    private Criteria lastSectionLaboratorysCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionLaboratorys(new Criteria())
     *
     * @throws TorqueException
     */
    public List getSectionLaboratorys() throws TorqueException
    {
        if (collSectionLaboratorys == null)
        {
            collSectionLaboratorys = getSectionLaboratorys(new Criteria(10));
        }
        return collSectionLaboratorys;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionLaboratorys from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getSectionLaboratorys(Criteria criteria) throws TorqueException
    {
        if (collSectionLaboratorys == null)
        {
            if (isNew())
            {
               collSectionLaboratorys = new ArrayList();
            }
            else
            {
                      criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid() );
                      collSectionLaboratorys = SectionLaboratoryPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid());
                      if (!lastSectionLaboratorysCriteria.equals(criteria))
                {
                    collSectionLaboratorys = SectionLaboratoryPeer.doSelect(criteria);
                }
            }
        }
        lastSectionLaboratorysCriteria = criteria;

        return collSectionLaboratorys;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionLaboratorys(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionLaboratorys(Connection con) throws TorqueException
    {
        if (collSectionLaboratorys == null)
        {
            collSectionLaboratorys = getSectionLaboratorys(new Criteria(10), con);
        }
        return collSectionLaboratorys;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionLaboratorys from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionLaboratorys(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collSectionLaboratorys == null)
        {
            if (isNew())
            {
               collSectionLaboratorys = new ArrayList();
            }
            else
            {
                       criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid());
                       collSectionLaboratorys = SectionLaboratoryPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid());
                       if (!lastSectionLaboratorysCriteria.equals(criteria))
                 {
                     collSectionLaboratorys = SectionLaboratoryPeer.doSelect(criteria, con);
                 }
             }
         }
         lastSectionLaboratorysCriteria = criteria;

         return collSectionLaboratorys;
     }

                        
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related SectionLaboratorys from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getSectionLaboratorysJoinSection(Criteria criteria)
        throws TorqueException
    {
        if (collSectionLaboratorys == null)
        {
            if (isNew())
            {
               collSectionLaboratorys = new ArrayList();
            }
            else
            {
                            criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid());
                            collSectionLaboratorys = SectionLaboratoryPeer.doSelectJoinSection(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid());
                        if (!lastSectionLaboratorysCriteria.equals(criteria))
            {
                collSectionLaboratorys = SectionLaboratoryPeer.doSelectJoinSection(criteria);
            }
        }
        lastSectionLaboratorysCriteria = criteria;

        return collSectionLaboratorys;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related SectionLaboratorys from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getSectionLaboratorysJoinClassroom(Criteria criteria)
        throws TorqueException
    {
        if (collSectionLaboratorys == null)
        {
            if (isNew())
            {
               collSectionLaboratorys = new ArrayList();
            }
            else
            {
                            criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid());
                            collSectionLaboratorys = SectionLaboratoryPeer.doSelectJoinClassroom(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SectionLaboratoryPeer.SECTIONID, getSectionid());
                        if (!lastSectionLaboratorysCriteria.equals(criteria))
            {
                collSectionLaboratorys = SectionLaboratoryPeer.doSelectJoinClassroom(criteria);
            }
        }
        lastSectionLaboratorysCriteria = criteria;

        return collSectionLaboratorys;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collSectionRecitations
     */
    protected List collSectionRecitations;

    /**
     * Temporary storage of collSectionRecitations to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initSectionRecitations()
    {
        if (collSectionRecitations == null)
        {
            collSectionRecitations = new ArrayList();
        }
    }

    /**
     * Method called to associate a SectionRecitation object to this object
     * through the SectionRecitation foreign key attribute
     *
     * @param l SectionRecitation
     * @throws TorqueException
     */
    public void addSectionRecitation(SectionRecitation l) throws TorqueException
    {
        getSectionRecitations().add(l);
        l.setSection((Section) this);
    }

    /**
     * The criteria used to select the current contents of collSectionRecitations
     */
    private Criteria lastSectionRecitationsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionRecitations(new Criteria())
     *
     * @throws TorqueException
     */
    public List getSectionRecitations() throws TorqueException
    {
        if (collSectionRecitations == null)
        {
            collSectionRecitations = getSectionRecitations(new Criteria(10));
        }
        return collSectionRecitations;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionRecitations from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getSectionRecitations(Criteria criteria) throws TorqueException
    {
        if (collSectionRecitations == null)
        {
            if (isNew())
            {
               collSectionRecitations = new ArrayList();
            }
            else
            {
                      criteria.add(SectionRecitationPeer.SECTIONID, getSectionid() );
                      collSectionRecitations = SectionRecitationPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(SectionRecitationPeer.SECTIONID, getSectionid());
                      if (!lastSectionRecitationsCriteria.equals(criteria))
                {
                    collSectionRecitations = SectionRecitationPeer.doSelect(criteria);
                }
            }
        }
        lastSectionRecitationsCriteria = criteria;

        return collSectionRecitations;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSectionRecitations(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionRecitations(Connection con) throws TorqueException
    {
        if (collSectionRecitations == null)
        {
            collSectionRecitations = getSectionRecitations(new Criteria(10), con);
        }
        return collSectionRecitations;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related SectionRecitations from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSectionRecitations(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collSectionRecitations == null)
        {
            if (isNew())
            {
               collSectionRecitations = new ArrayList();
            }
            else
            {
                       criteria.add(SectionRecitationPeer.SECTIONID, getSectionid());
                       collSectionRecitations = SectionRecitationPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(SectionRecitationPeer.SECTIONID, getSectionid());
                       if (!lastSectionRecitationsCriteria.equals(criteria))
                 {
                     collSectionRecitations = SectionRecitationPeer.doSelect(criteria, con);
                 }
             }
         }
         lastSectionRecitationsCriteria = criteria;

         return collSectionRecitations;
     }

                        
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related SectionRecitations from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getSectionRecitationsJoinSection(Criteria criteria)
        throws TorqueException
    {
        if (collSectionRecitations == null)
        {
            if (isNew())
            {
               collSectionRecitations = new ArrayList();
            }
            else
            {
                            criteria.add(SectionRecitationPeer.SECTIONID, getSectionid());
                            collSectionRecitations = SectionRecitationPeer.doSelectJoinSection(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SectionRecitationPeer.SECTIONID, getSectionid());
                        if (!lastSectionRecitationsCriteria.equals(criteria))
            {
                collSectionRecitations = SectionRecitationPeer.doSelectJoinSection(criteria);
            }
        }
        lastSectionRecitationsCriteria = criteria;

        return collSectionRecitations;
    }
                  
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related SectionRecitations from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getSectionRecitationsJoinClassroom(Criteria criteria)
        throws TorqueException
    {
        if (collSectionRecitations == null)
        {
            if (isNew())
            {
               collSectionRecitations = new ArrayList();
            }
            else
            {
                            criteria.add(SectionRecitationPeer.SECTIONID, getSectionid());
                            collSectionRecitations = SectionRecitationPeer.doSelectJoinClassroom(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(SectionRecitationPeer.SECTIONID, getSectionid());
                        if (!lastSectionRecitationsCriteria.equals(criteria))
            {
                collSectionRecitations = SectionRecitationPeer.doSelectJoinClassroom(criteria);
            }
        }
        lastSectionRecitationsCriteria = criteria;

        return collSectionRecitations;
    }
                            


                          
            
    /**
     * Collection to store aggregation of collGradesheets
     */
    protected List collGradesheets;

    /**
     * Temporary storage of collGradesheets to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initGradesheets()
    {
        if (collGradesheets == null)
        {
            collGradesheets = new ArrayList();
        }
    }

    /**
     * Method called to associate a Gradesheet object to this object
     * through the Gradesheet foreign key attribute
     *
     * @param l Gradesheet
     * @throws TorqueException
     */
    public void addGradesheet(Gradesheet l) throws TorqueException
    {
        getGradesheets().add(l);
        l.setSection((Section) this);
    }

    /**
     * The criteria used to select the current contents of collGradesheets
     */
    private Criteria lastGradesheetsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getGradesheets(new Criteria())
     *
     * @throws TorqueException
     */
    public List getGradesheets() throws TorqueException
    {
        if (collGradesheets == null)
        {
            collGradesheets = getGradesheets(new Criteria(10));
        }
        return collGradesheets;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related Gradesheets from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getGradesheets(Criteria criteria) throws TorqueException
    {
        if (collGradesheets == null)
        {
            if (isNew())
            {
               collGradesheets = new ArrayList();
            }
            else
            {
                      criteria.add(GradesheetPeer.SECTIONID, getSectionid() );
                      collGradesheets = GradesheetPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(GradesheetPeer.SECTIONID, getSectionid());
                      if (!lastGradesheetsCriteria.equals(criteria))
                {
                    collGradesheets = GradesheetPeer.doSelect(criteria);
                }
            }
        }
        lastGradesheetsCriteria = criteria;

        return collGradesheets;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getGradesheets(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getGradesheets(Connection con) throws TorqueException
    {
        if (collGradesheets == null)
        {
            collGradesheets = getGradesheets(new Criteria(10), con);
        }
        return collGradesheets;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section has previously
     * been saved, it will retrieve related Gradesheets from storage.
     * If this Section is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getGradesheets(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collGradesheets == null)
        {
            if (isNew())
            {
               collGradesheets = new ArrayList();
            }
            else
            {
                       criteria.add(GradesheetPeer.SECTIONID, getSectionid());
                       collGradesheets = GradesheetPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(GradesheetPeer.SECTIONID, getSectionid());
                       if (!lastGradesheetsCriteria.equals(criteria))
                 {
                     collGradesheets = GradesheetPeer.doSelect(criteria, con);
                 }
             }
         }
         lastGradesheetsCriteria = criteria;

         return collGradesheets;
     }

                  
              
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Section is new, it will return
     * an empty collection; or if this Section has previously
     * been saved, it will retrieve related Gradesheets from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Section.
     */
    protected List getGradesheetsJoinSection(Criteria criteria)
        throws TorqueException
    {
        if (collGradesheets == null)
        {
            if (isNew())
            {
               collGradesheets = new ArrayList();
            }
            else
            {
                            criteria.add(GradesheetPeer.SECTIONID, getSectionid());
                            collGradesheets = GradesheetPeer.doSelectJoinSection(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(GradesheetPeer.SECTIONID, getSectionid());
                        if (!lastGradesheetsCriteria.equals(criteria))
            {
                collGradesheets = GradesheetPeer.doSelectJoinSection(criteria);
            }
        }
        lastGradesheetsCriteria = criteria;

        return collGradesheets;
    }
                            


          
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("Sectionid");
              fieldNames.add("Sectionname");
              fieldNames.add("Numberofstudents");
              fieldNames.add("Courseid");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("Sectionid"))
        {
                return new Integer(getSectionid());
            }
          if (name.equals("Sectionname"))
        {
                return getSectionname();
            }
          if (name.equals("Numberofstudents"))
        {
                return new Integer(getNumberofstudents());
            }
          if (name.equals("Courseid"))
        {
                return new Integer(getCourseid());
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(SectionPeer.SECTIONID))
        {
                return new Integer(getSectionid());
            }
          if (name.equals(SectionPeer.SECTIONNAME))
        {
                return getSectionname();
            }
          if (name.equals(SectionPeer.NUMBEROFSTUDENTS))
        {
                return new Integer(getNumberofstudents());
            }
          if (name.equals(SectionPeer.COURSEID))
        {
                return new Integer(getCourseid());
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getSectionid());
            }
              if (pos == 1)
        {
                return getSectionname();
            }
              if (pos == 2)
        {
                return new Integer(getNumberofstudents());
            }
              if (pos == 3)
        {
                return new Integer(getCourseid());
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(SectionPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    SectionPeer.doInsert((Section) this, con);
                    setNew(false);
                }
                else
                {
                    SectionPeer.doUpdate((Section) this, con);
                }
            }

                                      
                
            if (collSectionTeamTeachs != null)
            {
                for (int i = 0; i < collSectionTeamTeachs.size(); i++)
                {
                    ((SectionTeamTeach) collSectionTeamTeachs.get(i)).save(con);
                }
            }
                                          
                
            if (collSectionLectures != null)
            {
                for (int i = 0; i < collSectionLectures.size(); i++)
                {
                    ((SectionLecture) collSectionLectures.get(i)).save(con);
                }
            }
                                          
                
            if (collSectionLaboratorys != null)
            {
                for (int i = 0; i < collSectionLaboratorys.size(); i++)
                {
                    ((SectionLaboratory) collSectionLaboratorys.get(i)).save(con);
                }
            }
                                          
                
            if (collSectionRecitations != null)
            {
                for (int i = 0; i < collSectionRecitations.size(); i++)
                {
                    ((SectionRecitation) collSectionRecitations.get(i)).save(con);
                }
            }
                                          
                
            if (collGradesheets != null)
            {
                for (int i = 0; i < collGradesheets.size(); i++)
                {
                    ((Gradesheet) collGradesheets.get(i)).save(con);
                }
            }
                          alreadyInSave = false;
        }
      }


                          
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  sectionid ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setSectionid(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setSectionid(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getSectionid());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public Section copy() throws TorqueException
    {
        return copyInto(new Section());
    }
  
    protected Section copyInto(Section copyObj) throws TorqueException
    {
          copyObj.setSectionid(sectionid);
          copyObj.setSectionname(sectionname);
          copyObj.setNumberofstudents(numberofstudents);
          copyObj.setCourseid(courseid);
  
                    copyObj.setSectionid(0);
                              
                                      
                
        List v = getSectionTeamTeachs();
        for (int i = 0; i < v.size(); i++)
        {
            SectionTeamTeach obj = (SectionTeamTeach) v.get(i);
            copyObj.addSectionTeamTeach(obj.copy());
        }
                                                  
                
        v = getSectionLectures();
        for (int i = 0; i < v.size(); i++)
        {
            SectionLecture obj = (SectionLecture) v.get(i);
            copyObj.addSectionLecture(obj.copy());
        }
                                                  
                
        v = getSectionLaboratorys();
        for (int i = 0; i < v.size(); i++)
        {
            SectionLaboratory obj = (SectionLaboratory) v.get(i);
            copyObj.addSectionLaboratory(obj.copy());
        }
                                                  
                
        v = getSectionRecitations();
        for (int i = 0; i < v.size(); i++)
        {
            SectionRecitation obj = (SectionRecitation) v.get(i);
            copyObj.addSectionRecitation(obj.copy());
        }
                                                  
                
        v = getGradesheets();
        for (int i = 0; i < v.size(); i++)
        {
            Gradesheet obj = (Gradesheet) v.get(i);
            copyObj.addGradesheet(obj.copy());
        }
                    
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public SectionPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Section:\n");
        str.append("Sectionid = ")
           .append(getSectionid())
           .append("\n");
        str.append("Sectionname = ")
           .append(getSectionname())
           .append("\n");
        str.append("Numberofstudents = ")
           .append(getNumberofstudents())
           .append("\n");
        str.append("Courseid = ")
           .append(getCourseid())
           .append("\n");
        return(str.toString());
    }
}
